#pragma once
#include "Character/Part.h"
#include "ProtoBuffer/AllProtocol.h"
#include "Common/TableData/TreasureAdventureCfg.h"
#include "Treasure/TreasureMgr.h"
#include "Common/TreasureDefine.h"
#include "Common/Item/Item.h"

class TreasurePart : public Part
{
public:
	TreasurePart() : mTreasureState(TreasureStateEnum_End), mIndex(0){}
	virtual ~TreasurePart() {}

public:
	virtual bool	Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB = nullptr);
	virtual bool	UnInit();
	virtual bool	OnMsgHandle(uint32_t cmd, const char* data, uint32_t len);
	virtual bool	SaveDB(CharacterDBInfo& characterDB);
	virtual void	OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	virtual void	OnTimer(uint32_t nTimerId);
	virtual bool	SynOnLogin(PlayerClientInfo& playerInfo);

public:
	void			Compose(const char *data, uint32_t len);
	void			Active(const char *data, uint32_t len);
	void			UnActive(const char* data, uint32_t len);
	void			ActiveInfo(const char* data, uint32_t len);
	void			OnDig(const char *data, uint32_t len);
	void			DigDone();
	void			SetActiveIdx(uint32_t itemIdx);		//set active item grid index
	//GM 
	void			GM_DigDone(uint32_t itemIdx);

private:
	void			DoGame_Item(int32_t gameId);
	void			DoGame_Boss(int32_t gameId);
	void			DoGame_Thief(int32_t gameId);
	void			DoGame_Poison(int32_t gameId);
	bool			AddItem(uint32_t itemId, int32_t count, SItemSourceParam &sourceParam);
	void			SendEmail(LIST_ITEM itemList);
	void			RandMonster(MAP_UINT32_UINT32 &mons, uint32_t count);

private:
	TreasureStateEnum	mTreasureState;
	uint32_t			mIndex;
};